package com.nciae.controller;

import com.nciae.service.IElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IElasticSearchService elasticSearchService;

    @PutMapping("/{indexName}")
    public String createIndex(@PathVariable("indexName") String indexName) throws IOException {
        String index = elasticSearchService.createIndex(indexName);
        return index;
    }

    @GetMapping("/{indexName}")
    public String getIndex(@PathVariable("indexName")String indexName) throws IOException {
        String s = elasticSearchService.selectIndex(indexName);
        return s;
    }

    @GetMapping("/r1")
    public String r1() {
        String name = (String)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return name;
    }
}